#include "testSamples.h"
#include "XML/Noeud.h"
#include "XML/Balise.h"
#include "XML/Texte.h"
#include "DTD/tree/DtdTree.h"

Balise* generateXml(){

	Balise* catalog = new Balise("CATALOG", false);
	Balise* CD1 = new Balise("CD", false);
	catalog->ajouterFils(CD1);
	Balise* title1 = new Balise("TITLE", false);
	Balise* artist1 = new Balise("ARTIST", false);
	Balise* country1 = new Balise("COUNTRY", false);
	Balise* company1 = new Balise("COMPANY", false);
	Balise* price1 = new Balise("PRICE", false);
	Balise* year1 = new Balise("YEAR", false);
	CD1->ajouterFils(title1);
	CD1->ajouterFils(artist1);
	CD1->ajouterFils(country1);
	CD1->ajouterFils(company1);
	CD1->ajouterFils(price1);
	CD1->ajouterFils(year1);
	title1->ajouterFils(new Texte("Empire Burlesque"));
	artist1->ajouterFils(new Texte("Bob Dylan"));
	country1->ajouterFils(new Texte("USA"));
	company1->ajouterFils(new Texte("Colombia"));
	price1->ajouterFils(new Texte("10.90"));
	year1->ajouterFils(new Texte("1985"));

	Balise* CD2 = new Balise("CD", false);
	catalog->ajouterFils(CD2);
	Balise* title2 = new Balise("TITLE", false);
	Balise* artist2 = new Balise("ARTIST", false);
	/*
	artist2->ajouterAttribut(new Attribut("Nom", "francois"));
	artist2->ajouterAttribut(new Attribut("Prenom", "Premier"));
	artist2->ajouterAttribut(new Attribut("Age", "8"));
	*/
	Balise* country2 = new Balise("COUNTRY", false);
	Balise* company2 = new Balise("COMPANY", false);
	Balise* price2 = new Balise("PRICE", false);
	Balise* year2 = new Balise("YEAR", false);
	CD2->ajouterFils(title2);
	CD2->ajouterFils(artist2);
	CD2->ajouterFils(country2);
	CD2->ajouterFils(company2);
	CD2->ajouterFils(price2);
	CD2->ajouterFils(year2);
	title2->ajouterFils(new Texte("Hide your heart"));
	artist2->ajouterFils(new Texte("Bonnie Tyler"));
	country2->ajouterFils(new Texte("UK"));
	company2->ajouterFils(new Texte("CBS Records"));
	price2->ajouterFils(new Texte("9.90"));
	year2->ajouterFils(new Texte("1988"));
	
	Balise* CD3 = new Balise("CD", false);
	catalog->ajouterFils(CD3);
	Balise* title3 = new Balise("TITLE", false);
	Balise* artist3 = new Balise("ARTIST", false);
	Balise* country3 = new Balise("COUNTRY", false);
	Balise* company3 = new Balise("COMPANY", false);
	Balise* price3 = new Balise("PRICE", false);
	Balise* year3 = new Balise("YEAR", false);
	CD3->ajouterFils(title3);
	CD3->ajouterFils(artist3);
	CD3->ajouterFils(country3);
	CD3->ajouterFils(company3);
	CD3->ajouterFils(price3);
	CD3->ajouterFils(year3);
	title3->ajouterFils(new Texte("Greatest Hits"));
	artist3->ajouterFils(new Texte("Dolly Parton"));
	country3->ajouterFils(new Texte("USA"));
	company3->ajouterFils(new Texte("RSA"));
	price3->ajouterFils(new Texte("9.90"));
	year3->ajouterFils(new Texte("1982"));

	return catalog;
}

DtdTree* generateDtd()
{
	DtdTree *tree = new DtdTree();

	/* RACINE
	 */
	/* Déclaration de la racine */
	DtdDeclaration *root = new DtdDeclaration();
	root->name = "CATALOG";
	root->elementType = ELM_CHILDREN;
	tree->addDeclaration(root);
	/* Composite de la racine */
	DtdComposite *rootCmp = new DtdComposite();
	rootCmp->compositeType = SEQ;
	rootCmp->card = ONE;
	rootCmp->parent = NULL;
	root->tree = rootCmp;
	/* Élement CD */
	DtdElement *cdElm = new DtdElement();
	cdElm->name = "CD";
	cdElm->card = ZERO_PLUS;
	rootCmp->appendChild(cdElm);
	/* Déclaration de CD
	 */
	DtdDeclaration *cd = new DtdDeclaration();
	cd->name = "CD";
	cd->elementType = ELM_CHILDREN;
	tree->addDeclaration(cd);
	/* Composite de CD */
	DtdComposite *cdCmp = new DtdComposite();
	cdCmp->compositeType = SEQ;
	cdCmp->card = ONE;
	cdCmp->parent = NULL;
	cd->tree = cdCmp;
	/* Déclaration TITLE
	 */
	DtdDeclaration *titleDecl = new DtdDeclaration();
	titleDecl->name = "TITLE";
	titleDecl->elementType = ELM_PCDATA;
	titleDecl->tree = NULL;
	tree->addDeclaration(titleDecl);
	/* Element TITLE */
	DtdElement *titleElm = new DtdElement();
	titleElm->name = "TITLE";
	titleElm->card = ONE;
	cdCmp->appendChild(titleElm);
	/* Déclaration ARTIST
	 */
	DtdDeclaration *artistDecl = new DtdDeclaration();
	artistDecl->name = "ARTIST";
	artistDecl->elementType = ELM_PCDATA;
	artistDecl->tree = NULL;
	std::string attr = "Nom";
	artistDecl->addAttribut(attr);
	attr = "Prenom";
	artistDecl->addAttribut(attr);
	attr = "Age";
	artistDecl->addAttribut(attr);
	tree->addDeclaration(artistDecl);
	/* Element ARTIST */
	DtdElement *artistElm = new DtdElement();
	artistElm->name = "ARTIST";
	artistElm->card = ONE;
	cdCmp->appendChild(artistElm);
	/* Déclaration COUNTRY
	 */
	DtdDeclaration *countryDecl = new DtdDeclaration();
	countryDecl->name = "COUNTRY";
	countryDecl->elementType = ELM_PCDATA;
	countryDecl->tree = NULL;
	tree->addDeclaration(countryDecl);
	/* Element COUNTRY */
	DtdElement *countryElm = new DtdElement();
	countryElm->name = "COUNTRY";
	countryElm->card = ONE;
	cdCmp->appendChild(countryElm);
	/* Déclaration COMPANY
	 */
	DtdDeclaration *companyDecl = new DtdDeclaration();
	companyDecl->name = "COMPANY";
	companyDecl->elementType = ELM_PCDATA;
	companyDecl->tree = NULL;
	tree->addDeclaration(companyDecl);
	/* Element COMPANY */
	DtdElement *companyElm = new DtdElement();
	companyElm->name = "COMPANY";
	companyElm->card = ONE;
	cdCmp->appendChild(companyElm);
	/* Déclaration PRICE
	 */
	DtdDeclaration *priceDecl = new DtdDeclaration();
	priceDecl->name = "PRICE";
	priceDecl->elementType = ELM_PCDATA;
	priceDecl->tree = NULL;
	tree->addDeclaration(priceDecl);
	/* Element PRICE */
	DtdElement *priceElm = new DtdElement();
	priceElm->name = "PRICE";
	priceElm->card = ONE;
	cdCmp->appendChild(priceElm);
	/* Déclaration YEAR
	 */
	DtdDeclaration *yearDecl = new DtdDeclaration();
	yearDecl->name = "YEAR";
	yearDecl->elementType = ELM_PCDATA;
	yearDecl->tree = NULL;
	tree->addDeclaration(yearDecl);
	/* Element YEAR */
	DtdElement *yearElm = new DtdElement();
	yearElm->name = "YEAR";
	yearElm->card = ONE;
	cdCmp->appendChild(yearElm);

	tree->buildTreeStructure();

	return tree;
}

Balise* generateXSL()
{
	Balise* XSLStylesheet = new Balise("xsl:stylesheet", false);
	 
	/* Template de la racine
	 * <xsl:template match="/">
	 * 	<html>
	 * 		<body>
	 * 			<xsl:apply-templates/>  
	 * 		</body>
	 * 	</html>
	 * </xsl:template>
	 */
	Balise* rootTemplate = new Balise("xsl:template", false);
	XSLStylesheet->ajouterFils(rootTemplate);
	rootTemplate->ajouterAttribut(new Attribut("match", "/"));
	Balise *htmlB = new Balise("html", false);
	rootTemplate->ajouterFils(htmlB);
	Balise *bodyB = new Balise("body", false);
	htmlB->ajouterFils(bodyB);
	Balise *h2B = new Balise("h2", false);
	h2B->ajouterFils(new Texte("My CD Collection"));
	bodyB->ajouterFils(h2B);
	bodyB->ajouterFils(new Balise("xsl:apply-templates", true));
	 
	/* Template de CD
	 * <xsl:template match="cd">
  	 * 	<p>
     *			<xsl:apply-templates/>  
 	 * 	</p>
	 * </xsl:template>
	 */
	Balise* cdTemplate = new Balise("xsl:template", false);
	XSLStylesheet->ajouterFils(cdTemplate);
	cdTemplate->ajouterAttribut(new Attribut("match", "CD"));
	Balise *pB = new Balise("p", false);
	cdTemplate->ajouterFils(pB);
	pB->ajouterFils(new Balise("xsl:apply-templates", true));

	/* Template de TITLE
	 * <xsl:template match="title">
  	 * 	Title:
  	 *	<span style="color:#ff0000">
  	 * 		<xsl:apply-templates/>
  	 * </span>
     * <br />
	 * </xsl:template>
	 */
	Balise* titleTemplate = new Balise("xsl:template", false);
	XSLStylesheet->ajouterFils(titleTemplate);
	titleTemplate->ajouterAttribut(new Attribut("match", "TITLE"));
	titleTemplate->ajouterFils(new Texte("Title :"));
	Balise *spanB = new Balise("span", false);
	spanB->ajouterAttribut(new Attribut("style", "color:#ff0000"));
	titleTemplate->ajouterFils(spanB);
	spanB->ajouterFils(new Balise("xsl:apply-templates", true));
	titleTemplate->ajouterFils(new Balise("br", true));

	/* Template de ARTIST
	 * <xsl:template match="artist">
  	 * 	Artist:
  	 *	<span style="color:#00ff00">
  	 * 		<xsl:apply-templates/>
  	 * </span>
     * <br />
	 * </xsl:template>
	 */
	Balise* artistTemplate = new Balise("xsl:template", false);
	XSLStylesheet->ajouterFils(artistTemplate);
	artistTemplate->ajouterAttribut(new Attribut("match", "ARTIST"));
	artistTemplate->ajouterFils(new Texte("Artist :"));
	Balise *spanB2 = new Balise("span", false);
	spanB2->ajouterAttribut(new Attribut("style", "color:#00ff00"));
	artistTemplate->ajouterFils(spanB2);
	spanB2->ajouterFils(new Balise("xsl:apply-templates", true));
	artistTemplate->ajouterFils(new Balise("br", true));

	return XSLStylesheet;
}